import 'dart:typed_data';

import 'package:flutter/widgets.dart';
import 'package:get/get.dart';

import 'logcat.dart';

class Tools {
  //
  //从数组第N位取长度为L生成新数组
  //
  static Uint8List getUint8ListPart(Uint8List uint8list, int n, int l) {
    Uint8List newUint8List = Uint8List(l);
    for (int i = 0; i < l; i++) {
      newUint8List[i] = uint8list[n + i];
    }
    return newUint8List;
  }

  ///数组合并
  static Uint8List uint8ListMerge(
      Uint8List uint8list_start, Uint8List uint8list_end) {
    Uint8List newUint8List =
        Uint8List(uint8list_start.length + uint8list_end.length);
    for (int i = 0; i < uint8list_start.length; i++) {
      newUint8List[i] = uint8list_start[i];
    }
    for (int i = 0; i < uint8list_end.length; i++) {
      newUint8List[uint8list_start.length + i] = uint8list_end[i];
    }
    return newUint8List;
  }

  static int uint8ListToint32(Uint8List uint8list, {int s = 0}) {
    if (uint8list.length < (s + 4)) {
      Jm_log.e(
          "Tools", "uint8ListToint32:长度不够 , ${uint8list.length},$uint8list");
      return 0;
    }
    return (uint8list[0 + s] << 24) +
        (uint8list[1 + s] << 16) +
        (uint8list[2 + s] << 8) +
        uint8list[3 + s];
  }
}
